* confirmedrun.do JEP	01/26/15
* Program to avoid rerunning regressions if ster file already exists
* This is to be able to build the project a second time without re-running the regressions if the .ster files are already there

*************************** Change log ********************************** 

/*
		1/29/15		Export every time to register in project
		03/13/15	Add rerun override
		04/10/15	Add option to add industry fixed effects, but leave i.ccode and i.time by default
					Add regressions without CGM scheme
*/	


cap program drop confirmedrun
program confirmedrun
	syntax, name(string) rif(string) p(integer) r(string) sample(varname) [controls(string) register treat(varname) rerun fe(string) cluster(string) large rster]
	if "`treat'"=="" loc treat "treat"
	if "`fe'"=="" loc fe "i.ccode i.time"
	if "`cluster'"=="" loc cluster "ccode"
	cap confirm file "`name'_p`p'.ster"
	if (_rc | "`rerun'"=="rerun")  {
		cgmrif2 lw `treat' `fe' emp `controls' if `sample' , hyp(0) boot($boot) cluster(`cluster') x(`treat') i(ccode) t(time) q(`p') rif(`rif'`p')	`large'	
	}
	else {
		est use "`name'_p`p'.ster"
	}
	exportrif, name("`name'") p(`p') r(`r') `register' `rster'
end
